package cn.psvmc.cxzapi.controller.ticket;

import cn.psvmc.cxzapi.model.common.DelEntity;
import cn.psvmc.cxzapi.model.ticket.TTicketType;
import cn.psvmc.cxzapi.response.Result;
import cn.psvmc.cxzapi.response.ResultGenerator;
import cn.psvmc.cxzapi.service.ticket.TTicketTypeService;
import cn.psvmc.cxzapi.util.ToolUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 工单类型
 * @Author auto
 * @Date 2024-08-12
 */
@RestController
@RequestMapping("/ticket_type")
public class TTicketTypeController {

    @Resource
    private TTicketTypeService tTicketTypeService;

    /**
    * @Author auto 2024-08-12 新增工单类型表
    * @Param tTicketType 工单类型表
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/add")
    public Result add(@RequestBody TTicketType tTicketType) {
        int addResult = tTicketTypeService.add(tTicketType);
        if (addResult > 0) {
            return ResultGenerator.genSuccessResult("保存成功！");
        }
        return ResultGenerator.genFailResult("保存失败！");
    }

    /**
    * @Author auto 2024-08-12 更新工单类型表
    * @Param tTicketType 工单类型表模型
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/edit")
    public Result edit(@RequestBody TTicketType tTicketType) {
        ToolUtils.validation(new Object[]{tTicketType.getTypeId(), "id", 1, tTicketType.getRversion(), "版本", 1});
        int updateResult = tTicketTypeService.edit(tTicketType);
        if (updateResult > 0) {
            return ResultGenerator.genSuccessResult("更新成功！");
        }
        return ResultGenerator.genFailResult("更新失败！");
    }

    /**
    * @Author auto 2024-08-12 删除工单类型表
    * @Param [entity]
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/delete")
    public Result delete(@RequestBody DelEntity entity) {
        Integer id = entity.getId();
        Integer rversion = entity.getRversion();
        ToolUtils.validation(new Object[]{id, "id", 1, rversion, "版本", 1});
        int delResult = tTicketTypeService.delete(id, rversion);
        if (delResult > 0) {
            return ResultGenerator.genSuccessResult("删除成功！");
        }
        return ResultGenerator.genFailResult("删除失败！");
    }

    /**
     * @Description 管理列表
     * @Date 2024/8/13 14:12
     * @Author YWX
     * @Param []
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list")
    public Result list() {
        return ResultGenerator.genSuccessResult("查询成功！", tTicketTypeService.listAll());
    }

    /**
     * @Description 选择列表
     * @Date 2024/8/12 22:57
     * @Author YWX
     * @Param []
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list_sel")
    public Result listForSel() {
        return ResultGenerator.genSuccessResult("查询成功！", tTicketTypeService.listForSel());
    }
}
